import Vue from 'vue'
//时间戳过滤器
Vue.filter("filterDateForYear", function(value) {
	Date.prototype.toLocaleString = function() {
		return this.getFullYear() + '年';
	};
	if (value) {
		var unixTimestamp = new Date(value) ;
		return unixTimestamp.toLocaleString();
	}else{
		return '-年';
	}
  
});

function handleDate (format, value) {
  var _type = format
  var _date = new Date(value || '')
  return _type
    .replace(/(y{4})/, _date.getFullYear())
    .replace(/(M{2})/, function(){ return _date.getMonth() < 9 ? '0' + (_date.getMonth() + 1) : (_date.getMonth() + 1)})
    .replace(/d{2}/, function(){ return _date.getDate() < 10 ? '0' + (_date.getDate()) : _date.getDate()})
    .replace(/H{2}/, function(){ return _date.getHours() < 10 ? '0' + (_date.getHours()) : _date.getHours()})
    .replace(/m{2}/, function(){ return _date.getMinutes() < 10 ? '0' + (_date.getMinutes()) : _date.getMinutes()})
    .replace(/s{2}/, function(){ return _date.getSeconds() < 10 ? '0' + (_date.getSeconds()) : _date.getSeconds()})
}

Vue.filter("filterDateForMonth", function(value) {
  return handleDate('yyyy年MM月', value)
});
Vue.filter("filterDateForDay", function(value) {
  Date.prototype.toLocaleString = function() {
    return this.getFullYear() + "年" + ((this.getMonth()+1 >= 1 && this.getMonth()+1 <= 9) ? "0" + (this.getMonth()+1):this.getMonth()+1) + "月" +((this.getDate() >= 1 && this.getDate() <= 9) ? "0" + this.getDate():this.getDate()) + '日'
  };
  var unixTimestamp = new Date(value) ;
  return unixTimestamp.toLocaleString();
});
Vue.filter("filterDateForDayTime", function(value) {
  if (typeof 1 != typeof value ) {
    return '-'
  }
  Date.prototype.toLocaleString = function() {
    return this.getFullYear() + "-" + ((this.getMonth()+1 >= 1 && this.getMonth()+1 <= 9) ? "0" + (this.getMonth()+1):this.getMonth()+1) + "-" +((this.getDate() >= 1 && this.getDate() <= 9) ? "0" + this.getDate():this.getDate())
  };
  var unixTimestamp = new Date(value) ;
  return unixTimestamp.toLocaleString();
});

Vue.filter("filterCarFixedPriceState", function(value) {
  switch(value)
    {
    case 0:
      return '不是一口价';
      break;
    case 1:
      return '一口价';
      break;
    default:
      return '不是一口价';
      break;
    }
});
Vue.filter("filterCarTransferState", function(value) {
  switch(value)
    {
    case 0:
      return '不包含过户费';
      break;
    case 1:
      return '包含过户费';
      break;
    default:
      return '不包含过户费';
      break;
    }
});
Vue.filter("filterCar4sUpkeepState", function(value) {
  switch(value)
    {
    case 0:
      return '不是';
      break;
    case 1:
      return '是';
      break;
    default:
      return '不是';
      break;
    }
});
Vue.filter("filterImageName", function(value) {
  switch(value)
    {
    case 'vin':
      return 'VIN码';
      break;
    case 'right_rear':
      return '右后';
      break;
    case 'driving_seat':
      return '驾驶座椅';
      break;
    case 'control_booth':
      return '控制室';
      break;
    case 'odograph':
      return '里程表';
      break;
    case 'left_anterior':
      return '左前（首图）';
      break;
    case 'open_trunk':
      return '打开后备箱';
      break;
    case 'engine_bay':
      return '发动机全景';
      break;
    case 'right_side':
      return '右侧';
      break;
    case 'tyre':
      return '轮胎';
      break;
    case 'insurance':
      return '保单';
      break;
    case 'registration_license':
      return '登记证';
      break;
    case 'vehicle_license':
      return '行驶证';
      break;
    case 'gear_lever':
      return '变速挡杆';
      break;
    default:
      return '无';
      break;
    }
});
Vue.filter("filterCarStockState", function(value) {
  switch(value)
    {
    case 0:
      return '未入库';
      break;
    case 1:
      return '已驳回';
      break;
    case 2:
      return '已撤销';
      break;
    case 10:
      return '入库中';
      break;
    case 20:
      return '已入库';
      break;
    case 30:
      return '出库中';
      break;
    case 40:
      return '已出库';
      break;
    default:
      return '无';
      break;
    }
});

Vue.filter("filterCarDetectState", function(value) {
  switch(value)
    {
    case 0:
      return '未检测';
      break;
    case 10:
      return '检测中';
      break;
    case 20:
      return '已检测';
      break;
    default:
      return '无';
      break;
    }
});
Vue.filter("filterCarSaleState", function(value) {
  switch(value)
    {
    case 0:
      return '未上架';
      break;
    case 10:
      return '上架中';
      break;
    case 20:
      return '已上架';
      break;
    case 30:
      return '已下架';
      break;
    default:
      return '无';
      break;
    }
});
Vue.filter("filterCarAuthState", function(value) {
  switch(value)
    {
    case 0:
      return '未认证';
      break;
    case 10:
      return '已认证';
      break;
    default:
      return '无';
      break;
    }
});
Vue.filter("filterCarOrderState", function(value) {
  switch(value)
    {
    case 0:
      return '未预订';
      break;
    case 1:
      return '已预订';
      break;
    default:
      return '无';
      break;
    }
});
// 销售类型
Vue.filter("filterOrderSaleType",function(value){
	switch(~~value)
	{
		case 1:
			return '批发'
			break
		case 2:
			return '直销'
			break
		case 3:
			return '拍卖'
			break
		default:
			return ''
			break
	}
})
// 付款类型
Vue.filter("filterSalePayType",function(value){
	switch(~~value)
	{
	
		case 1:
			return '现款'
			break
		case 2:
			return '按揭'
			break	
		default:
			return ''
			break
	}
})
// 是否上牌
Vue.filter("filterCarLicenceStatus",function(value){
	switch(~~value){		
		case 1:
			return '已上牌'
			break
		case 2:
			return '未上牌'
			break
		case 3:
			return '新车'
			break
		default:
			return ''
			break
	}
})

// 年月 入 date
Vue.filter("filterDateForMonthTwo", function(value) {
  if ( typeof value === typeof 1){
    return handleDate('yyyy-MM', value)
  } else {
    return value
  }
});


Vue.filter("filterDateForDayTwo", function(value) {
  Date.prototype.toLocaleString = function() {
    return this.getFullYear() + "-" + ((this.getMonth()+1 >= 1 && this.getMonth()+1 <= 9) ? "0" + (this.getMonth()+1):this.getMonth()+1) + "-" +((this.getDate() >= 1 && this.getDate() <= 9) ? "0" + this.getDate():this.getDate()) 
  };
  var unixTimestamp = new Date(value) ;
  return unixTimestamp.toLocaleString();
});

// 是否上牌
Vue.filter("filterFollowState",function(value){
	switch(value){
		case 0:
      return '待分配'
      break
    case 1:
      return '待跟进'
      break
    case 10:
      return '跟进中'
      break
    case 20:
      return '已预约'
      break
    case 30:
      return '已战败'
      break
    case 40:
      return '已失效'
      break
    case 50:
      return '已成交'
      break
		default:
			return ''
			break
	}
})

// 跟进历史
Vue.filter("filterFollowHistory",function(value){
  switch(value){
    case 10:
      return '跟进'
      break
    case 20:
      return '预约'
      break
    case 30:
      return '战败'
      break
    case 40:
      return '失效'
      break
    case 50:
      return '成交'
      break
    default:
      return ''
      break
  }
})

Vue.filter("filterDateFormat",function(value){
  return String(value).slice(0,10)
})


Vue.filter('filterDatefavorite',function(value){
	var Time = new Date(value)
	var currentTime = new Date()
	var finalTime = Date.parse(currentTime)-value
	if(finalTime>0&&finalTime<8640000){
		return parseInt(finalTime/360000)+'小时前'
	}else if(finalTime>8640000&&finalTime<8640000*2){
		return '一天前'
	}else if(finalTime>8640000*2&&finalTime<8640000*3){
		return '两天前'
	}else{
		return Time.getFullYear() + "-" + ((Time.getMonth()+1 >= 1 && Time.getMonth()+1 <= 9) ? "0" + (Time.getMonth()+1):Time.getMonth()+1) + "-" +((Time.getDate() >= 1 && Time.getDate() <= 9) ? "0" + Time.getDate():Time.getDate())
	}
	
})

Vue.filter('filterCarDetectState', function(value) {
  switch(value){
    case 500:
      return '未初检'
      break
    case 510:
      return '初检不通过'
      break
    case 520:
      return '初检通过'
      break
    case 530:
      return '申请复检中'
      break
    case 540:
      return '复检完成'
      break
    default:
      return ''
      break
  }
})

Vue.filter('filterCarDetectStateTwo', function(value) {
  switch(value){
    case 10:
      return '待检测'
      break
    case 20:
      return '已检测'
      break
    default:
      return ''
      break
  }
})


Vue.filter('filterCarPurpose', function(value) {
  switch (value) {
    case 1:
      return '营运'
      break
    case 2:
      return '非营运'
      break
    case 3:
      return '营转非'
      break
    default: 
      return ''
      break
  }
})

Vue.directive('focus-to-top', {
  inserted: function (el) {
    el.onfocus = function () {
      setTimeout(function () {
        el.scrollIntoView(true)
      }, 500)
    }
  }
})








































